import { BASE_URL } from "@/utils/env.config";

const upload = options => {
    const { url, files = [], filePath, name, formData = {} } = options;
    return new Promise((resolve, reject) => {
        // console.log({ url, files, filePath, name, formData });
        wx.uploadFile({
            url: BASE_URL + url,
            filePath,
            name,
            formData,
            files,
            header: {
                "Content-Type": "multipart/form-data"
            },
            success: res => {
                const data = JSON.parse(res.data) || {};
                const { code } = data;
                if (code === "200") {
                    resolve(data.data);
                    return;
                }
                reject(data);
            },
            fail: err => {
                reject(err);
            }
        });
    });
};

export default upload;
